package com.producer.queue;


import com.producer.queue.bean.DataBean;
import com.producer.queue.define.TaskDefine;
import com.producer.thread.OutPutThread;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @Author : liu lin qin
 * @Date :  Created by pangoin on 2019/8/26.
 */
public class ChildQueue implements Runnable {
    private static final Log logger = LogFactory.getLog(ChildQueue.class);
    @Override
    public void run() {
        while (true){
            DataBean dataBean=null;
            try {
                dataBean= TaskDefine.childQueue.take();
                if (dataBean == null) {
                    Thread.sleep(2000);// 队列为空，消停一会 // 阻塞队列，这里不生效
                    logger.debug("childQueue data found in queue continue.");
                    continue;
                }
                do {
                    if(TaskDefine.threadPool.getActiveCount()>200){
                        Thread.sleep(2000);// 队列为空，消停一会 // 阻塞队列，这里不生效
                        logger.debug("childQueue TaskDefine threadPool ActiveCount >200 sleep 2000");
                        continue;
                    }else{
                        break;
                    }
                }while (true);
                TaskDefine.threadPool.execute(new OutPutThread(dataBean));
            } catch (InterruptedException e) {
                logger.debug("childQueue  InterruptedException"+e.getMessage());
            }
        }
    }
}
